import request from '@/utils/request'
import store from '@/store'

export function fetchList(query) {
  const user_id = store.getters.user_id;
  return request({
    url: `/api/${user_id}/categories`,
    // url: '/category/list',
    method: 'get',
    params: query
  })
}

export function fetchCategory(id) {
  return request({
    url: '/category/detail',
    method: 'get',
    params: { id }
  })
}

export function fetchPv(pv) {
  return request({
    url: '/category/pv',
    method: 'get',
    params: { pv }
  })
}

export function createCategory(data) {
  return request({
    url: '/category/create',
    method: 'post',
    data
  })
}

export function updateCategory(data) {
  return request({
    url: '/category/update',
    method: 'post',
    data
  })
}

export function deleteCategory(data) {
  return request({
    url: `/category/${data.id}`,
    method: 'delete'
  })
}
